﻿namespace BEGDC.CC.Web.UserControls
{
	using System;
	using System.Data;
	using System.Drawing;
	using System.Web;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;

	using BEGDC.CC.Entity;
	using BEGDC.CC.BL.Workflow;

	/// <summary>
	///		Summary description for Title.
	/// </summary>
	public class Title : System.Web.UI.UserControl
	{
		protected System.Web.UI.HtmlControls.HtmlTable tb_Project;
		protected System.Web.UI.HtmlControls.HtmlTable tb_BakupMenu;
		protected System.Web.UI.HtmlControls.HtmlTableCell td_Name;
		protected System.Web.UI.HtmlControls.HtmlTableCell td_Date;
		protected System.Web.UI.HtmlControls.HtmlTableCell td_BackupMenuItems;

		private void Page_Load(object sender, System.EventArgs e)
		{
			if (!this.IsPostBack)
			{
				CCIdentity identity = (CCIdentity)this.Page.User.Identity;

				string name;
//				if (GDC.CODM.Resource.BaseResource.Culture.Name == "zh-CN")
					name = identity.UserInfo.NameEN;
//				else
//					name = identity.UserInfo.EnglishName;

				if ((identity.Backupers != null) && (identity.Backupers.Count != 0))
				{
					if (identity.IsBackup)
					{
//						if (GDC.CODM.Resource.BaseResource.Culture.Name == "zh-CN")
							name += "["+identity.Backuper.NameEN+"]";
//						else
//							name += "["+identity.Backuper.EnglishName+"]";
					}
					this.td_Name.InnerHtml ="<A class=\"dropdown\" href=\"javascript:showHide(div_BackupMenu);\">"+name+"<span style=\"FONT-FAMILY: Webdings\">6</span> </A>";									
					this.InitialBackupMenu(identity);
				}
				else
					this.td_Name.InnerHtml = name;

//				this.td_Date.InnerHtml += DateTime.Now.ToString("D", GDC.CODM.Resource.BaseResource.Culture.DateTimeFormat);

				if (((this.Page.GetType().FullName == "ASP.WorkflowExecution_aspx") || (this.Page.GetType().FullName == "ASP.CCCWorkflow_aspx") )&& (this.Request.QueryString["QualNo"] != null))
				{
					this.tb_Project.Visible = true;
				}
				else
				{
					this.tb_Project.Visible = false;
				}
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void InitialBackupMenu(BEGDC.CC.BL.Workflow.CCIdentity identity)
		{
			string menu = "<table class=\"popupMenuTable\" width=\"100%\" cellpadding=\"2\" cellspacing=\"0\" id=\"tb_BakupMenu\" runat=\"server\">";
			menu += "	<tr>";
			menu += "					<td>";
			menu += "						<table height=\"100%\" cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\">";
			menu += "							<tr>";
			menu += "								<td width=\"25\">&nbsp;</td>";
			menu += "								<td class=\"popupMenuRow\" id=\"popupWin_Menu_Disable\" onmouseover=\"this.className='popupMenuRowHover';\"";
			menu += "								onmouseout=\"this.className='popupMenuRow';\" value=\"..\\Workflow\\SetBackuper.aspx?backupid=0\">&nbsp;"+"Backup"+"</td>";
			menu += "							</tr>";
			menu += "						</table>";
			menu += "					</td>";
			menu += "				</tr>";


			if (identity.Backupers != null)
			{
				for(int i=0; i<identity.Backupers.Count; i++)
				{
					Employee backuper = identity.Backupers[i] as Employee;
					menu += CreateBackupMenu(backuper);
				}
			}
			menu += "</table>";

			td_BackupMenuItems.InnerHtml = menu;
		}

		private string CreateBackupMenu(Employee backup)
		{
			string name;
//			if (GDC.CODM.Resource.BaseResource.Culture.Name == "zh-CN")
//				name = backup.OfficialName;
//			else
				name = "&nbsp;"+backup.NameEN;
			string strhtml = "<tr height=\"1\">";
			strhtml += "					<td>";
			strhtml += "						<div class=\"popupMenuSep\"><img height=\"1\"></div>";
			strhtml += "					</td>";
			strhtml += "</tr>";
			strhtml += "<tr>";
			strhtml += "	<td>";
            strhtml += " 	<table height=\"100%\" cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\">";
			strhtml += "	<tr>";
			strhtml += "	<td width=\"25\">&nbsp;</td>";
			strhtml += "	<td class=\"popupMenuRow\" id=\"popupWin_Menu_Disable\" onmouseover=\"this.className='popupMenuRowHover';\"";
			strhtml += "	onmouseout=\"this.className='popupMenuRow';\" value=\"..\\Workflow\\SetBackuper.aspx?backupid="+backup.Id.ToString()+"\">&nbsp;"+"GDC.CODM.Resource.WebMenu.SetBackup"+name+"</td>";
			strhtml += "	</tr>";
			
			strhtml += "	</table>";
			strhtml += "	</td>";
			strhtml += "	</tr>";
			return strhtml;
		}
	}
}
